package com.rock.code.system.roleModule.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.util.StringUtil;
import com.rock.code.base.service.impl.BaseServiceImpl;
import com.rock.code.common.comm.RandomGUID;
import com.rock.code.common.pager.Page;
import com.rock.code.system.roleModule.dao.TbSysRoleModuleDao;
import com.rock.code.system.roleModule.domain.TbSysRoleModule;
import com.rock.code.system.roleModule.service.TbSysRoleModuleService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 权限管理 Service 实现
 *
 * @author wangwenbo
 * @date 2018/01/15
 */
@Service
public class TbSysRoleModuleServiceImpl extends BaseServiceImpl<TbSysRoleModuleDao> implements TbSysRoleModuleService {

    @Resource
    private TbSysRoleModuleDao tbSysRoleModuleDao;

    /**
     * Insert.
     *
     * @param
     * @return the int
     * @throws Exception the exception
     * @author wangwenbo
     * @date 2018/01/15
     */
    @Override
    public int insert(TbSysRoleModule tbSysRoleModule) throws Exception {
        tbSysRoleModule.setRoleModuleId(RandomGUID.getRandomGUID());
        return tbSysRoleModuleDao.insert(tbSysRoleModule);
    }

    /**
     * Delete.
     *
     * @param primaryKey the primary key
     * @return the int
     * @throws Exception the exception
     * @author wangwenbo
     * @date 2018/01/15
     */
    @Override
    public int delete(String primaryKey) throws Exception {
        return tbSysRoleModuleDao.delete(primaryKey);
    }

    /**
     * Delete by param.
     *
     * @param param the param
     * @return the int
     * @throws Exception the exception
     * @author wangwenbo
     * @date 2018/01/15
     */
    @Override
    public int deleteByParam(Map<String, Object> param) throws Exception {
        return tbSysRoleModuleDao.deleteByParam(param);
    }

    /**
     * Update.
     *
     * @param
     * @return the int
     * @throws Exception the exception
     * @author wangwenbo
     * @date 2018/01/15
     */
    @Override
    public int update(TbSysRoleModule tbSysRoleModule) throws Exception {
        return tbSysRoleModuleDao.update(tbSysRoleModule);
    }

    @Override
    public TbSysRoleModule query(TbSysRoleModule tbSysRoleModule) throws Exception {
        return tbSysRoleModuleDao.query(tbSysRoleModule);
    }

    /**
     * Query by para map.
     *
     * @param param the param
     * @return the tbSysRolesMenu
     * @throws Exception the exception
     * @author wangwenbo
     * @date 2018/01/15
     */
    @Override
    public TbSysRoleModule queryByParaMap(Map<String, Object> param) throws Exception {
        return tbSysRoleModuleDao.queryByParaMap(param);
    }

    /**
     * Query list.
     *
     * @param
     * @return the list
     * @throws Exception the exception
     * @author wangwenbo
     * @date 2018/01/15
     */
    @Override
    public List<TbSysRoleModule> queryList(TbSysRoleModule tbSysRoleModule) throws Exception {
        return tbSysRoleModuleDao.queryList(tbSysRoleModule);
    }

    /**
     * Query list by para map.
     *
     * @param param the param
     * @return the list
     * @throws Exception the exception
     * @author wangwenbo
     * @date 2018/01/15
     */
    @Override
    public List<TbSysRoleModule> queryListByParaMap(Map<String, Object> param) throws Exception {
        return tbSysRoleModuleDao.queryListByParaMap(param);
    }

    /**
     * Query page list.
     *
     * @param param the param
     * @return the page info
     * @throws Exception the exception
     * @author wangwenbo
     * @date 2018/01/15
     */
    @Override
    public PageInfo queryPageList(Page page, Map<String, Object> param) throws Exception {
        String orderBy = "";
        if (!StringUtil.isEmpty(page.getSidx())) {
            orderBy = this.getOrderBy(page);
        }
        PageHelper.startPage(page.getPage(), page.getRows());
        if (!orderBy.equals("")) {
            PageHelper.orderBy(orderBy);
        }
        List<TbSysRoleModule> list = tbSysRoleModuleDao.queryListByParaMap(param);
        return new PageInfo(list);
    }

     /**
     * Query list by order.
     *
     * @param page  the page
     * @param param the param
     * @return the list
     * @throws Exception the exception
     * @author wangwenbo
     * @date 2018/01/15
     */
    public List<TbSysRoleModule> queryListByOrder(Page page, Map<String, Object> param) throws Exception {
        String orderBy = "";
        if (!StringUtil.isEmpty(page.getSidx())) {
            orderBy = this.getOrderBy(page);
        }
        if (!orderBy.equals("")) {
            param.put("orderBy", orderBy);
        }
        return tbSysRoleModuleDao.queryListByParaMap(param);
    }

    /**
     * Query list by order.
     *
     * @param page  the page
     * @param param the param
     * @return the list
     * @throws Exception the exception
     * @author wangwenbo
     * @date 2018/01/15
     */
    public List<TbSysRoleModule> queryTableListByOrder(Page page, Map<String, Object> param) throws Exception {
        String orderBy = "";
        if (!StringUtil.isEmpty(page.getSidx())) {
            orderBy = this.getOrderBy(page);
        }
        if (!orderBy.equals("")) {
            param.put("orderBy", orderBy);
        }
        return tbSysRoleModuleDao.queryTableListByParaMap(param);
    }

    /**
     * Query table page list.
     *
     * @param param the param
     * @return the page info
     * @throws Exception the exception
     * @author wangwenbo
     * @date 2018/01/15
     */
    public PageInfo queryTablePageList(Page page, Map<String, Object> param) throws Exception {
        String orderBy = "";
        if (!StringUtil.isEmpty(page.getSidx())) {
            orderBy = this.getOrderBy(page,"ExtendResultMap");
        }
        PageHelper.startPage(page.getPage(), page.getRows());
        if (!orderBy.equals("")) {
            PageHelper.orderBy(orderBy);
        }
        List<TbSysRoleModule> list = tbSysRoleModuleDao.queryTableListByParaMap(param);
        return new PageInfo(list);
    }
}